module.exports = function($scope, $resource, obj, $state, $modalInstance, $modal){

	console.log('device');

	$scope.obj = obj;

    console.log(obj);

    var url = '/api/as/wc/device/create';

    // if(angular.isUndefined(obj.id)){
    //     url = '/api/as/tc/device/create';
    // }else{
    //     url = '/api/as/tc/device/update';
    // }


	$scope.gogo = function(){

        var para = {
            'code' : $scope.obj.code,
            'pas' : $scope.obj.pas,
            'view' : obj.view,
            'type' : 1,
            'state' : 1,
            'del_flg' : 0,
            'auth_state' : 0,
            'many_state' : 1,
            'group_auth_state' : 1,
        };

        if(angular.isDefined(obj.id)){
            para['id'] = $scope.obj.id;
        }

        console.log(para);

		$resource(url, {}, {}).save(para, function (res) {
			console.log(res);

			if (res.errcode !== 0) {
				alert(res.errmsg);
				return;
			}
			alert("保存成功");
			$modalInstance.close();

		});
	};

	$scope.cancel = function(){

		$modalInstance.close();

	}

};
